package com.fly.core.config;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;

import org.springframework.web.WebApplicationInitializer;

/**
 * 
 * 2种方式注册H2Console
 * 
 * @author 00fly
 * @version [版本号, 2023年4月13日]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@WebServlet(value = "/h2-console/*", initParams = {@WebInitParam(name = "webAllowOthers", value = "true")})
public class H2Console extends org.h2.server.web.WebServlet implements WebApplicationInitializer
{
    private static final long serialVersionUID = 570039364013171073L;
    
    @Override
    public void onStartup(ServletContext servletContext)
        throws ServletException
    {
        org.h2.server.web.WebServlet h2Console = new org.h2.server.web.WebServlet();
        Dynamic servlet = servletContext.addServlet("h2Console", h2Console);
        servlet.setInitParameter("webAllowOthers", "true");
        servlet.setLoadOnStartup(2);
        servlet.addMapping("/h2/*");
    }
}